package ywpt.service.config;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.QuyuInfo;
import ywpt.web.common.PublicFunction;
@Service("quyuService")
public class QuyuServiceImpl extends HibernateEntityDao<QuyuInfo> implements QuyuService{
	public QuyuServiceImpl () {
		
	}

	@Override
	public String createQuyuCode() {
		DetachedCriteria query = DetachedCriteria.forClass(QuyuInfo.class, "quyu");
		String quyuCode="";
		String code="";
		Integer maxId=new Integer(0);
		query.addOrder(Order.desc("id"));
		List<QuyuInfo> quyuInfos = this.getQuyuInfos(query);
		if ( quyuInfos.iterator().hasNext() )	
		{
			code = quyuInfos.iterator().next().getCode();		
			maxId = new Integer(code);
		}
		quyuCode=PublicFunction.getNextCode("", maxId, false,3); 
		return quyuCode;
	}

	@Override
	public QuyuInfo getQuyuInfoById(Long id) {
		return this.get(id);
	}

	@Override
	public int getQuyuInfoCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<QuyuInfo> getQuyuInfos(DetachedCriteria query, int pageSize,
			int startIndex) {
		return this.findAllByCriteria(query, pageSize, startIndex);
	}

	@Override
	public List<QuyuInfo> getQuyuInfos() {
		return this.getAll();
	}

	@Override
	public void removeQuyuInfo(Long id) {
		this.removeById(id);
	}

	@Override
	public void saveQuyuInfo(QuyuInfo quyuInfo) {
		this.save(quyuInfo);
	}

	@Override
	public void updatQuyuInfo(QuyuInfo quyuInfo) {
		this.update(quyuInfo);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<QuyuInfo> getQuyuInfos(DetachedCriteria query) {
		return this.findAllByCriteria(query);
	}
}
